package com.gosophia.govDoc.action.turning;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.security.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;

import com.gosophia.commons.web.action.BaseSupportAction;
import com.gosophia.commons.web.logAnnotation.LogRecord;
import com.gosophia.govDoc.common.TurningAction;
import com.gosophia.govDoc.dto.DocumentJobDataDTO;
import com.gosophia.govDoc.ws.DocumentTurningWebService;
import com.gosophia.springsecurity.UserDetailsImpl;
import com.opensymphony.xwork2.ActionContext;

@Scope("prototype")
@Controller("SubmitNextApprovalAction")
public class SubmitNextApprovalAction extends BaseSupportAction{//用于审批页面【同意并提交】按钮

	private static final long serialVersionUID = 4576842153000301890L;

	private final Logger logger = Logger.getLogger(this.getClass());
	
	private Long jobId;
	
	private DocumentJobDataDTO detailData;
	
	private String fromFlag;
	
	@Autowired
	private DocumentTurningWebService documentTurningWebService;
	
	@LogRecord(eventAction = "文档置办-同意并提交", eventTarget = "detailData")
	@Override
	public String _execute() throws Exception {
		   //取到当前的操作用户
  		UserDetailsImpl userDetails = (UserDetailsImpl) SecurityContextHolder
		.getContext().getAuthentication().getPrincipal();
  		detailData.setOperatorDTO(userDetails.getUserAccountDTO().getUserInfoDTO());
  		logger.debug("进入提交下一个审批人Action的文档版本:=>"+ detailData.getDocumentVersion());
		documentTurningWebService.handleDocumentTurning(jobId, detailData, TurningAction.SUBMIT_NEXT_APPROVAL);
		super.getRequestResult().setRsltCode("0");
		super.getRequestResult().setMessage("文档提交给下一审批人成功");
		ActionContext.getContext().getSession().put("_lastOpResult", super.getRequestResult());
        if("task".equals(fromFlag)){
            return "TASK";
        }else{
            return SUCCESS;  
        }
	}

	public void setDetailData(DocumentJobDataDTO detailData) {
		this.detailData = detailData;
	}

	public DocumentJobDataDTO getDetailData() {
		return detailData;
	}

	public void setJobId(Long jobId) {
		this.jobId = jobId;
	}

	public Long getJobId() {
		return jobId;
	}

    public String getFromFlag() {
        return fromFlag;
    }

    public void setFromFlag(String fromFlag) {
        this.fromFlag = fromFlag;
    }
	
	
}
